package domain

type StructInfo struct {
	CodeFile    *CodeFileInfo `json:"-"`
	LineNO      int
	Name        string
	Fields      []*FieldInfo
	Methods     []*MethodInfo
	Annotations []*AnnotationInfo
}

func NewStructInfo() *StructInfo {
	it := new(StructInfo)
	it.Fields = []*FieldInfo{}
	it.Methods = []*MethodInfo{}
	it.Annotations = []*AnnotationInfo{}
	return it
}

func (me *StructInfo) AppendField(lineNO int, name string, dataType string) {
	fld := NewFieldInfo()
	fld.Struct = me
	fld.LineNO = lineNO
	fld.Name = name
	fld.DataType = dataType
	me.Fields = append(me.Fields, fld)
}

func (me *StructInfo) AppendMethod(method *MethodInfo) {
	me.Methods = append(me.Methods, method)
}

func (me *StructInfo) AppendAnnotation(ant *AnnotationInfo) {
	me.Annotations = append(me.Annotations, ant)
}

func (me *StructInfo) Clone() interface{} {
	it := new(StructInfo)
	it.CodeFile = me.CodeFile
	it.LineNO = me.LineNO
	it.Name = me.Name

	it.Fields = make([]*FieldInfo, len(me.Fields))
	for i, v := range me.Fields {
		it.Fields[i] = v.Clone().(*FieldInfo)
		it.Fields[i].Struct = it
	}

	it.Methods = make([]*MethodInfo, len(me.Methods))
	for i, v := range me.Methods {
		it.Methods[i] = v.Clone().(*MethodInfo)
		it.Methods[i].Struct = it
	}

	it.Annotations = make([]*AnnotationInfo, len(me.Annotations))
	for i, v := range me.Annotations {
		it.Annotations[i] = v.Clone().(*AnnotationInfo)
	}

	return it
}
